package cn.stylefeng.guns.modular.cb.config;

import cn.stylefeng.guns.sys.modular.consts.model.params.SysConfigParam;
import cn.stylefeng.guns.sys.modular.consts.model.result.SysConfigResult;
import cn.stylefeng.guns.sys.modular.consts.service.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 阿里云 文件上传服务
 */
@Component
public class OSSConfig {

    public static String END_POINT;//地域节点
    public static String ACCESS_KEY_ID;//
    public static String ACCESS_KEY_SECRET;
    public static String BUCKET_NAME;

//    @Value("${aliyun.oss.endpoint}")
//    private void setEndpoint(String endpoint){
//        END_POINT = endpoint;
//    }
//
//    @Value("${aliyun.oss.accessKeyId}")
//    private void setAccessKeyId(String accessKeyId){
//        ACCESS_KEY_ID = accessKeyId;
//    }
//
//    @Value("${aliyun.oss.accessKeySecret}")
//    private void setAccessKeySecret(String accessKeySecret){
//        ACCESS_KEY_SECRET = accessKeySecret;
//    }
//
//    @Value("${aliyun.oss.bucketName}")
//    private void setBucketName(String bucketName){
//        BUCKET_NAME = bucketName;
//    }

    @Autowired
    private SysConfigService sysConfigService;

    @Bean
    public void init(){
        SysConfigParam sysConfigParam = new SysConfigParam();
        sysConfigParam.setName("OSS");
        List<SysConfigResult> sysConfigResultList = sysConfigService.findListBySpec(sysConfigParam);
        for (SysConfigResult sysConfig: sysConfigResultList) {
            if ("END_POINT".equals(sysConfig.getCode())){
                END_POINT = sysConfig.getValue();
            }else if ("ACCESS_KEY_ID".equals(sysConfig.getCode())){
                ACCESS_KEY_ID = sysConfig.getValue();
            }else if ("ACCESS_KEY_SECRET".equals(sysConfig.getCode())){
                ACCESS_KEY_SECRET = sysConfig.getValue();
            }else if ("BUCKET_NAME".equals(sysConfig.getCode())){
                BUCKET_NAME = sysConfig.getValue();
            }
        }
    }
}
